-[__NSCFArray objectForKeyedSubscript:] error?

Posted by jckly on Stack Overflow See other posts from Stack Overflow or by jckly
Published on 2014-05-27T15:16:26Z Indexed on 2014/05/27 15:25 UTC
Read the original article Hit count: 1959

Filed under:

I'm trying to get the data from a JSON response object in my iOS app after I log in. I keep getting this error though.

Error:

'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x8fc29b0'

Here is my code for the request, I'm using AFNetworking:

self.operation = [manager GET:urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary *JSON = (NSDictionary *)responseObject;
            NSDictionary *user = JSON[@"user"];
            NSString *token = user[@"auth_token"];
            NSString *userID = user[@"id"];
//            NSString *avatarURL = user[@"avatar_url"];
//            weakSelf.credentialStore.avatarURL = avatarURL;
            weakSelf.credentialStore.authToken = token;
            weakSelf.credentialStore.userId = userID;
            weakSelf.credentialStore.username = self.usernameField.text;
            weakSelf.credentialStore.password = self.passwordField.text;
            [SVProgressHUD dismiss];
            [self dismissViewControllerAnimated:YES completion:nil];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if (operation.isCancelled) {
                return;
            }
            [SVProgressHUD showErrorWithStatus:@"Login Failed"];
            NSLog(@"%@", error);
        }]; 

What the JSON response object looks like logged:

<__NSCFArray 0x8cac0b0>(
{
    user =     {
        "auth_token" = b3a18e0fb278739649a23f0ae325fee1e29fe5d6;
        email = "[email protected]";
        id = 1;
        username = jack;
    };
}
)

I'm converting the array to a Dictionary using pointers like this:

NSDictionary *JSON = (NSDictionary *)responseObject;

I'm new to iOS, apologies if problem is obvious.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about ios